package main

func search(nums []int, target int) int {
	return halfSearch(0, len(nums)-1, nums, target)
}

func halfSearch(low, high int, nums []int, target int) int {
	mid := (high + low) / 2
	if nums[mid] == target {
		return mid
	}
	if low > high {
		return -1
	}

	if nums[mid] > target {
		// 在左边
		return halfSearch(low, mid-1, nums, target)
	} else {
		return halfSearch(mid+1, high, nums, target)
	}
}

func main() {
	search([]int{1, 2, 3}, 1)
}
